﻿using System;
using System.Linq;
using System.Text;
using System.Web.UI;
using SBACN.WebSite.Cache;
using SBACN.WebSite.Code;

namespace SBACN.WebSite.UC
{
	public partial class EnHeader : BaseControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				InitCtrl();
			}
		}

		private void InitCtrl()
		{
			StringBuilder sb = new StringBuilder();
			sb.AppendLine("<ul>");
			sb.AppendLine("<li" + (Request.Path.ToLower().Trim().Trim('/') == "en/index.aspx" ? " class=\"a\" " : string.Empty) + "><a href=\"/en/Index.aspx\">Home</a></li>");
			var headerList = SystemMapCache.Instance.List.Where(p => p.Code.Length == 4 && p.ShowInMap && !string.IsNullOrWhiteSpace(p.EURL)).ToList();
			foreach (var item in headerList)
			{
				sb.AppendLine("<li" + ((item.Code == MenuCode) ? " class=\"a\" " : string.Empty) + "><a href=\"" + BasePage.UrlAppendQueryString(item.EURL, "st", item.Code, false) + "\">" + item.EText + "</a></li>");
			}
			sb.AppendLine("</ul>");
			this.nv.InnerHtml = sb.ToString();
		}

		protected void btn_Logout_Click(object sender, EventArgs e)
		{
			//if (MemberBasePage.UserInfo != null)
			{
				Session.Clear();
				Session.Abandon();
				Response.Redirect(BasePage.MemberDefaultPage, true);
			}
		}
	}
}